package api

import (
	"github.com/cihub/seelog"
	"github.com/gin-gonic/gin"
	"shop/entity"
	"shop/service"
	"shop/utils/result"
	"shop/utils/sessionutil"
)

func GetUserInfo(ctx *gin.Context) {
	user := service.GetUserInfo(sessionutil.GetUserIdFromCtx(ctx))
	result.RenderResult(ctx, result.Ok(user))
}

func UpdateUser(ctx *gin.Context) {
	form := new(entity.UserFilter)
	if err := ctx.ShouldBindJSON(form); err != nil {
		seelog.Errorf("invalid parameter, err: %v", err)
		result.RenderResult(ctx, result.Fail("参数格式错误"))
		return
	}

	result.RenderResult(ctx, service.UpdateUser(form, sessionutil.GetUserIdFromCtx(ctx)))
}
